﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pavilion
{
    public class PolygonCollisionData
    {
        private bool hasChanged;
        private Action<PolygonCollisionData> collisionChangedAction;

        internal PhysicalData PhysicalData { get; private set; }
        public List<PolygonPhysicalData> InteresectedPolygons { get; private set; }

        public PolygonCollisionData(PhysicalData physicalData, Action<PolygonCollisionData> collisionChangedAction)
        {
            this.PhysicalData = physicalData;
            this.collisionChangedAction = collisionChangedAction;

            InteresectedPolygons = new List<PolygonPhysicalData>();
        }

        internal void NotifyIntersectionChanged()
        {
            if (hasChanged)
            {
                hasChanged = false;
                this.collisionChangedAction.Invoke(this);
            }
        }

        internal void AddPolygon(PolygonPhysicalData polygonData)
        {
            if (!InteresectedPolygons.Contains(polygonData))
            {
                InteresectedPolygons.Add(polygonData);
                hasChanged = true;
            }
        }

        internal void RemovePolygon(PolygonPhysicalData polygonData)
        {
            if (InteresectedPolygons.Remove(polygonData))
                hasChanged = true;
        }
    }
}
